gpNamespace.TopLayer = cc.Layer.extend({
	userNameLabel:null,
	goldNum:null,
	diamondNum:null,
	voucherNum:null,
	goldAvi:null,
	diamondAvi:null,
	voucherAvi:null,

	numY:663,//顶部数字y轴

	labelColor:cc.color.WHITE,

	ctor:function(){
		this._super();
		this.init();
	},

		init:function(){
			ccs.armatureDataManager.addArmatureFileInfo(
					gpNamespace.goldAnimationRes.Gold_png,
					gpNamespace.goldAnimationRes.Gold_plist,
					gpNamespace.goldAnimationRes.Gold_json);
			ccs.armatureDataManager.addArmatureFileInfo(
					gpNamespace.diamondAnimationRes.Diamond_png,
					gpNamespace.diamondAnimationRes.Diamond_plist,
					gpNamespace.diamondAnimationRes.Diamond_json);
			ccs.armatureDataManager.addArmatureFileInfo(
					gpNamespace.dhqAnimationRes.Dhq_png,
					gpNamespace.dhqAnimationRes.Dhq_plist,
					gpNamespace.dhqAnimationRes.Dhq_json);
	
	
			var size = cc.winSize;
			var topLen=20;
			var leftLen=60;
			var middleLen=20;//顶部按钮间距
	
			//用户头像背景
			var userHeadBg=new cc.MenuItemImage(gpNamespace.mainSenceFirst.MiddleLayerListItemUserBg,gpNamespace.mainSenceFirst.MiddleLayerListItemUserBg,this.showUserInfo,this);
			userHeadBg.attr({
				x: leftLen,
				y: size.height-userHeadBg.width/2-topLen,
			});
	
	//		this.addChild(userHeadBg,2);
			//用户名字背景
			var nameBg=new cc.MenuItemImage(gpNamespace.mainSenceFirst.TopLayerTouxiangName,gpNamespace.mainSenceFirst.TopLayerTouxiangName,this.showUserInfo,this);
			nameBg.attr({
				x: userHeadBg.getPositionX()+nameBg.width/2,
				y: userHeadBg.getPositionY()
			});
	//		this.addChild(nameBg);
	
			//用户名字
			this.userNameLabel = new cc.LabelTTF("", gpNamespace.DEFAULTFONT, 30);
			this.userNameLabel.setFontFillColor(this.labelColor);
			this.userNameLabel.attr({
				x: nameBg.getPositionX(),
				y: nameBg.getPositionY()+5,
			});
			this.addChild(this.userNameLabel,3);
	//		this.userNameLabel = userNameLabel;
	
			//金币
			var goldBg = new cc.MenuItemImage(gpNamespace.mainSenceFirst.TopLayerJinBi,gpNamespace.mainSenceFirst.TopLayerJinBi,this.gotoScfunction, this);
			goldBg.attr({
				x: nameBg.getPositionX()+nameBg.width/2+goldBg.width/2+middleLen,
				y: userHeadBg.getPositionY(),
			});
			goldBg.setUserData(2);
			var goldAvi = new ccs.Armature("dh_cdd_zjm_jinbi");
			goldAvi.getAnimation().playWithIndex(0);
			goldAvi.getAnimation().setSpeedScale(1);
			goldAvi.setScale(1.01);
			goldAvi.setAnchorPoint(0, 0);
			goldAvi.setPosition(-2.4, 3.4);
			this.goldAvi = goldAvi;
			goldBg.addChild(goldAvi,3);
			goldAvi.getAnimation().setMovementEventCallFunc(null, this);
	
	//		this.scheduleFlush(goldAvi);
	
	//钻石
			var diamondBg = new cc.MenuItemImage(gpNamespace.mainSenceFirst.TopLayerBaoShi,gpNamespace.mainSenceFirst.TopLayerBaoShi, this.gotoScfunction, this);
			diamondBg.attr({
				x: goldBg.getPositionX()+goldBg.width/2+diamondBg.width/2+middleLen,
				y: userHeadBg.getPositionY(),
			});
			diamondBg.setUserData(4);
			var diamondAvi = new ccs.Armature("dh_cdd_zjj_zuanshidonghua");
			diamondAvi.getAnimation().playWithIndex(0);
			diamondAvi.getAnimation().setSpeedScale(1);
			diamondAvi.setScale(1);
			diamondAvi.setAnchorPoint(0, 0);
			diamondAvi.setPosition(0, 0);
			this.diamondAvi = diamondAvi;
			diamondBg.addChild(diamondAvi,3);
			diamondAvi.getAnimation().setMovementEventCallFunc(null, this);
			//this.scheduleFlush(diamondAvi);
			
			//兑换
			var voucherBg = new cc.MenuItemImage(gpNamespace.mainSenceFirst.TopLayerDuiHuanQuan,gpNamespace.mainSenceFirst.TopLayerDuiHuanQuan,this.gotoScfunction, this);
			voucherBg.attr({
				x: diamondBg.getPositionX()+diamondBg.width/2+voucherBg.width/2+middleLen,
				y: userHeadBg.getPositionY(),
			});
			var voucherAvi = new ccs.Armature("dh_cdd_zjm_duihuanquan");
			voucherAvi.getAnimation().playWithIndex(0);
			voucherAvi.getAnimation().setSpeedScale(1);
			voucherAvi.setScale(1);
			voucherAvi.setAnchorPoint(0, 0);
			voucherAvi.setPosition(0, 0);
			this.voucherAvi = voucherAvi;
			voucherBg.addChild(voucherAvi,3);
			voucherAvi.getAnimation().setMovementEventCallFunc(null, this);
			
			//this.scheduleFlush(voucherAvi);
			
			//设置
			var settingBg = new cc.MenuItemImage(
					gpNamespace.mainSenceFirst.TopLayerSetting,
					gpNamespace.mainSenceFirst.TopLayerSetting,
					function (sender) {
						cc.log("设置显示");
						tyNamespace.setMenuEnable(sender);
						gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
						var runningScene = cc.director.getRunningScene();
						var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
						var modelLayer = new tyNamespace.ModelLayer(70);
						modelLayer.setTouchArea(cc.size(874, 560), cc.p(202, 72));
						modelLayerCancelable.addChild(modelLayer);
						runningScene.addChild(modelLayerCancelable, 10);
						var szLayer = new gpNamespace.SettingLayer();
						szLayer.attr({
							//左上角坐标
							x: 0,
							y: cc.winSize.height,
						});
						modelLayer.addChild(szLayer);
						tyNamespace.AnimationManager.nodeJumpShow(szLayer, -cc.winSize.height);
					}, this);
			settingBg.attr({
				x: voucherBg.getPositionX()+voucherBg.width/2+settingBg.width/2+middleLen,
				y: userHeadBg.getPositionY(),
			});
			
			var topnameMenu = new cc.Menu(nameBg,userHeadBg,settingBg);
			topnameMenu.x = 0;
			topnameMenu.y = 0;
			topnameMenu.anchorX = 0;
			topnameMenu.anchorY = 0;
			this.addChild(topnameMenu);
			
			var topMoneyMenu = new cc.Menu(goldBg,diamondBg,voucherBg);
			topMoneyMenu.x = 0;
			topMoneyMenu.y = 8;
			topMoneyMenu.anchorX = 0;
			topMoneyMenu.anchorY = 0;
			this.addChild(topMoneyMenu);
			
			this.schedule(function(){
				this.animationSchedule(2,[goldAvi,diamondAvi,voucherAvi]);
			}, 8);
			
			gpNamespace.TyNetManager.getInstance().setTopLayer(this);
//			this.setUserHead(gpNamespace.QQInfo.HEADURL);//加载用户头像
	},

	/*scheduleFlush:function(node, time) {
    	var haveTime = time != null;

    	if (!haveTime) {
    		var fTime = Math.random() * 10;
    		time = 1 + parseInt(fTime);
//    		cc.log("scheduleFlush node:" + node + ",time:" + time + ",fTime:" + fTime);
    	}

    	var self = this;
    	node.scheduleOnce(function() {
    		node.getAnimation().playWithIndex(0);

    		var nextTime = null;
    		if (haveTime)
    			nextTime = time;

    		self.scheduleFlush(node, nextTime);
    	}, time);
    },*/

	animationSchedule:function(delay,sender) {    
		this.scheduleOnce(function(){sender[0].getAnimation().playWithIndex(0);},2);
		this.scheduleOnce(function(){sender[1].getAnimation().playWithIndex(0);},4);
		this.scheduleOnce(function(){sender[2].getAnimation().playWithIndex(0);},6);
	},

	gotoScfunction:function(sender){
		//xinyou.netManager.inPhysicalExchange();//获取商城实物奖品的信息
		cc.log("狗to商城");
		tyNamespace.setMenuEnable(sender);
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
		var index = sender.getUserData();
		var runningScene = cc.director.getRunningScene();
		var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
		var modelLayer = new tyNamespace.ModelLayer(70);
		modelLayer.setTouchArea(cc.size(1210, 570), cc.p(35, 35));
		modelLayerCancelable.addChild(modelLayer);
		runningScene.addChild(modelLayerCancelable, 10);
		var scLayer = null;
		if(index){
			scLayer = new gpNamespace.ScLayer(index);
		}else{
			scLayer = new gpNamespace.ScLayer();
		}
		scLayer.attr({
			//左上角坐标
			x: 0,
			y: cc.winSize.height
		});
		modelLayer.addChild(scLayer);
		tyNamespace.AnimationManager.nodeJumpShow(scLayer, -cc.winSize.height);
	},

	setUserNameLabel: function (userName) {
		this.userNameLabel.setString(userName);
	},

	setUserGold: function (string) {
//		this.goldNum.setString(string);
		//第四个参数最好不写，因为如果传3，可能会出现“000”的情况
		if(this.getChildByTag(101)){
			this.getChildByTag(101).reloadNum(string);
		}else{
			var goldLayer=new tyNamespace.NumLayer(string,18,0,"sz_cdd_js_");
			goldLayer.setPosition(465,this.numY);
			this.addChild(goldLayer, 2, 101);
		}
		
	},

	setUserDiamond: function (string) {
//		this.diamondNum.setString(string);
		if(this.getChildByTag(102)){
			this.getChildByTag(102).reloadNum(string);
		}else{
			var diamondLayer=new tyNamespace.NumLayer(string,18,0,"sz_cdd_js_");
			diamondLayer.setPosition(750,this.numY);
//			diamondLayer.anchorX = 0;
			this.addChild(diamondLayer, 2, 102);
		}
	},

	setUserVoucher: function (string) {
//		this.voucherNum.setString(string);
		if(this.getChildByTag(103)){
			this.getChildByTag(103).reloadNum(string);
		}else{
			var voucherLayer=new tyNamespace.NumLayer(string,18,0,"sz_cdd_js_");
			voucherLayer.setPosition(1040,this.numY);
			//    	diamondLayer.anchorX = 0;
			this.addChild(voucherLayer, 2, 103);
		}
	},

	showUserInfo:function(sender){
		cc.log("个人信息显示");
//		xinyou.netManager.getInnerUserInfo();

		tyNamespace.setMenuEnable(sender);
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
		var runningScene = cc.director.getRunningScene();
		var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
		var modelLayer = new tyNamespace.ModelLayer(70);
		modelLayer.setTouchArea(cc.size(1050, 570), cc.p(110, 50));
		modelLayerCancelable.addChild(modelLayer);
		runningScene.addChild(modelLayerCancelable, 10);
		var userInfoLayer = new gpNamespace.UserInfoLayer();
		userInfoLayer.attr({
			//左上角坐标
			x: 0,
			y: cc.winSize.height,
		});
		modelLayer.addChild(userInfoLayer);
		tyNamespace.AnimationManager.nodeJumpShow(userInfoLayer, -cc.winSize.height);
	},

	showVip:function(){
		var vip=new cc.Sprite(gpNamespace.mainSenceFirst.TopLayerVip);
		vip.attr({
			x: 90,
			y: 625,
			rotation: -45
		});
		this.addChild(vip,3);
	},
	
/*	addUserHead: function (texture) {
		var imgSprite;
		if (!texture) {
			imgSprite = new cc.Sprite(gpNamespace.xinzeng.QQ);
		}
		else {
			imgSprite = new cc.Sprite();
			imgSprite.initWithTexture(texture);
		}
		imgSprite.setScale(78 / imgSprite.getContentSize().width, 78 / imgSprite.getContentSize().height);
		imgSprite.setAnchorPoint(0, 0);
		imgSprite.setPosition(23, 615);
		imgSprite.setName("userHead");
		this.addChild(imgSprite,0);
	},

	setUserHead: function (headImgUrl) {
		var userHead = this.getChildByName("userHead");
		userHead && userHead.removeFromParent(true);

		tyNamespace.loadImgByUrl(headImgUrl, this.addUserHead, this);
		//xzgbNamespace.loadImgByUrl("http://q.qlogo.cn/g?b=qq&nk=1109980012&s=100", this.addUserHead, this);
	},*/

});